local commodityId = KEYS[1];
local customerId = KEYS[2];
local remainingQuantity = redis.call("get","spike.commodity:"..commodityId);

-- 校验商品
if (type(remainingQuantity) == "nil") then
    return 2;
end

-- 校验库存
if (tonumber(remainingQuantity) < 1) then
    return 1;
end

-- 出货
redis.call("decr","spike.commodity:"..commodityId);
redis.call("sadd","spike.customer:"..commodityId,customerId);
return 0;